package com.gxa.feedback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.R;
import com.gxa.common.entity.platform_maintenance_service1001.Feedback;
import com.gxa.feedback.mapper.FeedBackMapper;
import com.gxa.feedback.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FeedBackServiceImpl implements FeedBackService {

    @Autowired
    private FeedBackMapper feedBackMapper;


    @Override
    public R selectFeedBackByPage(Integer currentPage, Integer pageSize) {
        R r = new R();
        QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
        Page<Feedback> feedbackPage = new Page<>(currentPage,pageSize);
        Page<Feedback> selectPage = feedBackMapper.selectPage(feedbackPage, queryWrapper);
        r.setCode(200);
        r.setMessage("查询分页成功");
        r.setData(selectPage);
        return r;
    }


    @Override
    public R updateFeedBackByStatus(Feedback feedback) {
        R r = new R();
        Feedback selectById = feedBackMapper.selectById(feedback.getId());
        if(selectById.getStatus() == 0){
            r.setMessage("不用做处理");
        }else if(selectById.getStatus() == 1){
            selectById.setStatus(0);
            r.setCode(200);
            r.setMessage("处理成功");
            r.setData(selectById);
        }
        return r;
    }

    @Override
    public R selectFeedBackByCondition(Feedback feedback) {
        R r = new R();
        List<Feedback> feedbackList = feedBackMapper.selectFeedBackByCondition(feedback);
        r.setMessage("条件查询成功");
        r.setCode(200);
        r.setData(feedbackList);
        return r;
    }
}
